package com.lelouch.concurrency.theartofconcurrency.interrupt;

import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;

/**
 * @author lcy
 * @create 2018-08-23 14:54
 */
public class InterruptExample3 {
    public static class ReaderThread extends Thread
    {
        public static final int BUFFER_SIZE=512;
        Socket socket;
        InputStream is;

        public ReaderThread(Socket socket) throws IOException
        {
            this.socket=socket;
            is=this.socket.getInputStream();
        }

        @Override
        public void interrupt() {
            try
            {
                socket.close();
            }catch(IOException e)
            {

            }finally
            {
                super.interrupt();
            }
            super.interrupt();
        }
        @Override
        public void run() {
            try
            {
                byte[]buf=new byte[BUFFER_SIZE];
                while(true)
                {
                    int count=is.read(buf);
                    if(count<0)
                        break;
                    else if(count>0)
                    {

                    }
                }
            }catch(IOException e)
            {

            }
        }
    }

}
